package com.ty.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.common.util.StringUtil;
import com.ty.dao.CustomerDao;
import com.ty.entity.Customer;
import com.ty.service.CustomerService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * (Customer)表服务实现类
 *
 * @author makejava
 * @since 2020-12-01 22:17:48
 */
@Service("customerService")
public class CustomerServiceImpl extends ServiceImpl<CustomerDao, Customer> implements CustomerService {

    @Override
    public void saveCustomer(Customer customer) {
        if (StringUtil.isNull(customer.getName()))
            customer.setName(customer.getPhone());
        customer.setScore("0");
        customer.setSex("男");
        customer.setCreatetime(new Date());
        this.baseMapper.insert(customer);
    }

    @Override
    public PageInfo<Customer> getPage(Customer customer, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Customer> list = this.baseMapper.selectList(new QueryWrapper<>(null));
        PageInfo<Customer> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer queryByPhone(String phone) {
        return this.queryByPhone(phone);
    }
}